Skip to main content

Spellhandler Reference Guide

This definitive guide covers every aspect of the spellhandling system in PAL, including object creation, properties, functions, and traits.

Table of Contents

  1. Spellhandler Namespace
  2. Spell Object Creation
  3. Spell Object Properties
  4. Utility Functions
  5. Spell Traits
  6. Spell Object Methods

Spellhandler Namespace

The spellhandler functionality is contained within the LT.spellhandling namespace.

LT.spellhandling = LT.spellhandling or {
spellbooks = {} ---@type table<string, table<string, Spell>>
}

The spellbooks table contains all the spellbooks for different classes, organized by class name.

Spell Object Creation

NewSpell(spellID, payload)

Creates a new spell object.

local spell = LT.spellhandling.NewSpell(12345, {
ignoreCasting = false,
ignoreChanneling = false,
ignoreCost = false,
ignoreFacing = false,
ignoreMoving = false,
isSkillshot = false,
maxOffset = 0,
minOffset = 0,
nextMelee = false,
radius = 0,
queued = false,
timeToHit = 0
})

This function creates a new Spell object with the given spell ID and optional payload. The payload can be used to set various properties of the spell object.

Spell Object Properties

These properties can be set when creating a new spell object or using the setPayload method:

  • spellID: The ID of the spell (required)
  • ignoreCasting: If true, the spell can be cast while casting other spells
  • ignoreChanneling: If true, the spell can be cast while channeling other spells
  • ignoreCost: If true, the spell's resource cost is ignored when checking if it's castable
  • ignoreFacing: If true, the spell can be cast without facing the target
  • ignoreMoving: If true, the spell can be cast while moving
  • isSkillshot: If true, the spell is treated as a skillshot ability, affecting how it's cast
  • maxOffset: Maximum offset for skillshot abilities, used in calculating the spell's trajectory
  • minOffset: Minimum offset for skillshot abilities, used in calculating the spell's trajectory
  • nextMelee: If true, the spell is considered a melee ability, affecting range checks
  • radius: The radius of effect for AoE spells, used in target selection and positioning
  • queued: If true, the spell can be queued for casting
  • timeToHit: The time it takes for the spell to hit the target after casting, used in predictive casting

Utility Functions

PopulateSpellbook(spells, class)

Populates the spellbook for a specific class with the provided spells.

LT.spellhandling.PopulateSpellbook({
ArcaneBlast = NewSpell(30451),
ArcaneMissiles = NewSpell(5143),
-- More spells...
}, "MAGE")

This function adds multiple spells to the spellbook for a specific class, making them easily accessible in rotations.

Spell Traits

These are properties that can be accessed directly on a spell object:

  • spellID: The unique identifier of the spell
  • name: The name of the spell
  • id: The numeric ID of the spell (same as spellID)
  • icon: The icon ID of the spell
  • minRange: The minimum range of the spell
  • maxRange: The maximum range of the spell
  • baseCastTime: The base cast time of the spell in milliseconds
  • known: A boolean indicating whether the player knows the spell
  • callback: The callback function associated with the spell
  • lastCallbackString: A string representation of the last callback execution (used for debugging)

These traits are typically set when the spell object is created or updated, and provide quick access to basic spell information.

Example usage:

local spellName = spell.name
local spellId = spell.id
local spellIcon = spell.icon
local isKnown = spell.known

Spell Object Methods

Callback(function)

Sets a callback function for the spell.

spell:Callback(function(spell, unit, logic)
-- Spell casting logic here
end)

This method sets the callback function that will be executed when the spell is cast. The callback receives the spell object, the target unit, and an optional logic parameter.

Cast(unit)

Attempts to cast the spell on the specified unit.

if spell:Cast(target) then
-- Spell was successfully cast
end

This method checks if the spell is castable on the target and, if so, casts it. It returns true if the spell was successfully cast.

Castable(unit)

Checks if the spell can be cast on the specified unit.

if spell:Castable(target) then
-- Spell can be cast on the target
end

This method performs a series of checks to determine if the spell can be cast on the target, including range, line of sight, cooldown, and resource checks.

execute(unit, logic)

Executes the spell's callback function.

if spell:execute(target, "some_logic") then
-- Spell's callback was executed successfully
end

This method calls the spell's callback function with the specified unit and logic. It's used to implement custom casting behavior.

ready()

Checks if the spell is ready to be cast.

if spell:ready() then
-- Spell is ready to be cast
end

This method checks if the spell is usable and off cooldown.

GetCooldown()

Returns the remaining cooldown of the spell in seconds.

local cd = spell:GetCooldown()

This method calculates the remaining cooldown by subtracting the elapsed time since the cooldown started from the total cooldown duration.

IsUsable()

Checks if the spell is currently usable.

local isUsable, insufficientPower = spell:IsUsable()

This method checks if the spell can be used based on various factors such as having enough resources, not being on cooldown, and meeting other requirements.

Cost()

Returns the resource cost of the spell.

local cost = spell:Cost()

This method retrieves the current resource cost of the spell, which may vary based on talents or buffs.

ChargesLeft()

Returns the number of charges left for spells with charges.

local charges = spell:ChargesLeft()

For spells with charges, this method calculates the current number of charges, including fractional charges based on recharge time.

GetCurrentCastTime()

Returns the current cast time of the spell.

local castTime = spell:GetCurrentCastTime()

This method retrieves the current cast time of the spell, which may be affected by haste or other modifiers.

GetCharges()

Returns the current number of charges for the spell.

local currentCharges = spell:GetCharges()

This method returns the current whole number of charges for spells with a charge system.

GetMaxCharges()

Returns the maximum number of charges for the spell.

local maxCharges = spell:GetMaxCharges()

This method returns the maximum number of charges a spell can have.

fullRechargeTime()

Returns the time until all charges are recharged.

local rechargeTime = spell:fullRechargeTime()

For spells with charges, this method calculates the time it will take for all charges to be fully recharged.

GetTimeToCharges(numCharges)

Returns the time until a specific number of charges are available.

local timeToCharges = spell:GetTimeToCharges(2)

This method calculates the time it will take to reach a specific number of charges, considering current charges and recharge rate.

hasRangeCheck()

Checks if the spell has a range check.

if spell:hasRangeCheck() then
-- Spell has a range check
end

This method determines if the spell has a minimum or maximum range, indicating whether range checks are necessary.

IsInRange(unit)

Checks if the target unit is in range for the spell.

if spell:IsInRange(target) then
-- Target is in range
end

This method checks if the target unit is within the spell's cast range, considering both minimum and maximum range if applicable.

WillIntercept(target_or_x, y, z, radius)

Checks if the spell will intercept the target or a specific point.

if spell:WillIntercept(target) then
-- Spell will intercept the target
end

For skillshot spells, this method calculates if the spell's trajectory will intersect with the target or a specified point, considering the spell's radius.

WillKnockIntercept(unit, x1, y1, z1, x2, y2, z2, knockback_range, radius, hitbox)

Checks if the spell will knock and intercept a unit.

if spell:WillKnockIntercept(unit, x1, y1, z1, x2, y2, z2, 10, 5, true) then
-- Spell will knock and intercept the unit
end

This complex method calculates if a knockback spell will intercept a unit, considering the initial position, knockback distance, and spell radius.

currentGCD()

Returns the current global cooldown.

local gcd = spell:currentGCD()

This method retrieves the current global cooldown duration, which may be affected by haste.

wasLastCast()

Checks if this spell was the last spell cast.

if spell:wasLastCast() then
-- This spell was the last one cast
end

This method checks if the current spell was the most recently cast spell by the player.

isCurrentCast()

Checks if this spell is currently being cast.

if spell:isCurrentCast() then
-- This spell is currently being cast
end

This method checks if the player is currently casting this spell.

isCurrentChannel()

Checks if this spell is currently being channeled.

if spell:isCurrentChannel() then
-- This spell is currently being channeled
end

This method checks if the player is currently channeling this spell.

CastableDebug(unit)

Performs a debug check to see why a spell might not be castable.

spell:CastableDebug(target)

This method runs through all castability checks and prints debug information about why a spell might not be castable on a target.

CastableAOE(x, y, z)

Checks if the spell can be cast as an AoE at the specified coordinates.

if spell:CastableAOE(x, y, z) then
-- Spell can be cast as AoE at the specified location
end

This method checks if the spell can be cast as an AoE ability at the given coordinates, considering range, line of sight, and other factors.

Click(x, y, z)

Attempts to click the spell at the specified coordinates.

if spell:Click(x, y, z) then
-- Spell was successfully clicked at the location
end

This method simulates clicking the spell at the specified world coordinates, useful for ground-targeted abilities.

CastAOE(unit_or_x, y, z)

Attempts to cast the spell as an AoE on a unit or at specified coordinates.

if spell:CastAOE(target) then
-- Spell was successfully cast as AoE on the target
end

This method attempts to cast the spell as an AoE ability, either on a unit or at specified coordinates.

setSpellID(spellIDs)

Sets the spell ID for the spell. If multiple spell IDs are provided, the last spell ID in the list that is known will be used.

spell:setSpellID({12345, 67890})

This method updates the spell ID, which is useful for spells that change based on talents or specialization.

setPayload(payload)

Sets the payload for the spell.

spell:setPayload({ignoreCast = true, radius = 10})

This method updates the spell's properties based on the provided payload.

setSpellInfo()

Updates the spell information based on the current spell ID.

spell:setSpellInfo()

This method refreshes all the spell's information (name, icon, ranges, etc.) based on the current spell ID.

IsKnown()

Checks if the spell is known by the player.

if spell:IsKnown() then
-- Player knows this spell
end

This method checks if the player has learned or has access to this spell.

CanAfford()

Checks if the player has enough resources to cast the spell.

if spell:CanAfford() then
-- Player can afford to cast this spell
end

This method checks if the player has sufficient resources (mana, energy, etc.) to cast the spell.

This definitive guide covers every aspect of the spellhandling system in PAL, including object creation, properties, methods, utility functions, and traits. Use this comprehensive reference to maximize the potential of your combat routines and spell management in PAL.